﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ANZ_AIM_DAL;
using ANZ_AIM_BLL.Model;
using ANZ_AIM_BLL.Utils;
using ANZ_AIM_FRAMEWORK;
using System.Data;
using System.Data.OleDb;

namespace ANZ_AIM_BLL
{
    public class MasterDataBLL
    {
        private string ConnectionString;
        private const string TABLE_NAME = "MasterData";
        private Dictionary<string, string> ObjectPropDict;

        public MasterDataBLL()
        {
            ConnectionString = DBHelper.GetMainMdbConnectionString();
            this.ObjectPropDict = BuildObjectPropertyMapping();
        }

        public DataTable GetById(string masterId)
        {
            try
            {
                var dict = MiscHelper.Clone(this.ObjectPropDict);
                MasterData masterData = new MasterData() { MasterID = masterId };
                OleDbParameter[] parameters;
                var conditionDict = new Dictionary<string, string>
                    {
                        {"MasterID", "MasterID"}
                    };
                string command = CommandHelper.BuildSelectCommand(masterData, dict, conditionDict, out parameters);
                DataSet dsResult = OleDbHelper.ExecuteDataset(this.ConnectionString, CommandType.Text, command, parameters);

                return dsResult.Tables[0];
            }
            catch (Exception ex) { throw; }
        }

        public Dictionary<string, string> BuildObjectPropertyMapping()
        {
            Dictionary<string, string> dictionary = new Dictionary<string, string>
            {
                {"MasterID", "MasterID"},
                {"KeyValue", "KeyValue"},
                {"Description", "Description"},
            };

            return dictionary;
        }
    }
}
